package gagnatech.database;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Database {

	private static Database uniqueInstance;
	private String PERSISTENCE_UNIT_NAME = "GagnatechPU";

	private EntityManagerFactory emf;
	private EntityManager entityManager;

	private Database() {
		emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
		entityManager =emf.createEntityManager();
	}

	 public static synchronized Database getInstance() {
		 
		if(uniqueInstance==null) uniqueInstance = new Database();

	    return uniqueInstance;
     }

	public EntityManager getEntityManager() {
		return entityManager;
	}

	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	public EntityManagerFactory getEmf() {
		return emf;
	}

	public void setEmf(EntityManagerFactory emf) {
		this.emf = emf;
	}
	
	
	
}
